package com.example.captcha.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import jakarta.servlet.http.HttpServletResponse;
import lombok.val;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-22
 * Time: 17:36
 */

@RestController
@RequestMapping("/captcha")
public class HuToolCaptchaController {
    public void getCaptcha(HttpServletResponse response) throws IOException {
//        长200，宽100，验证码的数量是4位，线性干扰数量150
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100, 4, 150);
//        图形验证码写出到流
        lineCaptcha.write(response.getOutputStream());
        System.out.println("生成的验证码："+lineCaptcha);

    }


}
